package com.lei.controller;


import com.lei.bean.OV;
import com.lei.bean.User;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.servlet.ModelAndView;

import java.io.File;
import java.io.IOException;
import java.util.Date;
import java.util.List;


/**
 * @ClassName QuickController
 * @Description TODO
 * @Author Admin
 * @Date 2021/8/17 16:18
 * @Version 1.0
 */
@Controller
@RequestMapping("user")
public class QuickController {

    @RequestMapping("quick14")
    @ResponseBody
    //前端的参数名称和后端的名称要相同，不然就用@RequestParam(value="前端参数名称")
    public void save14(String name, @RequestParam(value = "uploadFile") MultipartFile[] multipartFile) throws IOException {
        //System.out.println(name);
        for (MultipartFile file : multipartFile) {
            String originalFilename = file.getOriginalFilename();
            System.out.println(originalFilename);
           file.transferTo(new File("d:\\upload\\"+originalFilename));
        }
    }
    @RequestMapping("quick13")
    @ResponseBody
    public void save13(@RequestHeader(value = "Accept",required = false) String accept){
        System.out.println(accept);
    }
    @RequestMapping("quick12")
    @ResponseBody
    public void save12(@RequestHeader(value = "User-Agent",required = false) String user_agent){
        System.out.println(user_agent);
    }
    @RequestMapping("quick11")
    @ResponseBody
    public void save11(Date date){
        System.out.println(date);
    }
    //参数绑定注解@requestParam
    @RequestMapping("quick10")
    @ResponseBody
    public void save10(@RequestParam(value = "name",required = true,defaultValue = "雷锋") String username){
        System.out.println(username);
    }

    @RequestMapping("quick9")
    @ResponseBody
    public void save9(@RequestBody List<User> userList){
        System.out.println(userList);
    }

    @RequestMapping("quick8")
    @ResponseBody
    public void save8(OV ov){
        System.out.println(ov.getUserList());
    }

    @RequestMapping("quick7")
    @ResponseBody
    public void save7(User user){
        System.out.println(user);
    }

    @RequestMapping("quick6")
    @ResponseBody
    public void save6(String name,int age){
        System.out.println(name);
        System.out.println(age);
    }

    @RequestMapping("quick5")
    @ResponseBody
    public void save5(User user){
        System.out.println(user);
    }

    @RequestMapping("quick4")
    @ResponseBody
    public String save4(){
        return "hell了";
    }

    @RequestMapping("quick3")
    public String save3(Model model){
        model.addAttribute("username","xxx");
        return "succeed";
    }

    @RequestMapping("quick2")
    public ModelAndView save2(){
        ModelAndView modelAndView=new ModelAndView();
        modelAndView.setViewName("succeed");
        return modelAndView;
    }

    @RequestMapping(value = "quick")
    public String save(){
        System.out.println("save running.....");
        return "succeed";
    }
}
